﻿using System;
using System.Collections.Generic;
using System.Text;
using DO.Common;
using DO.Domain.Repositories;
using DO.Domain.Entities;
using DO.Common.DTOs;
namespace DO.Domain
{
    public class Customer:EntityBase
    {

        //CJQ? The protected scope makes all the properties protected?
        protected Customer()
        {
        }
        //Borrado por implementación de entity base
        //public long Id { get; private set; }
        public long IdIdentification { get; protected set; }
        public string Name1 { get; protected set; }
        public string Name2 { get; protected set; }

        //CJNotes: Repository was created to decouple entity 
        //This is a factory method
        //The following i necessary and possible because the Customer class constructor is protected
        /*Refactoring was made according to chapter 2*/
        #region Refactored Create
        public static Customer Create(IRepositoryLocator repositorylocator, CustomerDTO operationDTO)
        {

            var instance = new Customer
            {

                Name1 = operationDTO.Name1,
                Name2 = operationDTO.Name2,
                IdIdentification = operationDTO.IdIdentification
            };
            /*ex-repositorie*/
            repositorylocator.Save(instance);
            return instance;
        }
        #endregion

        public void Update(IRepositoryLocator repositorylocator, CustomerDTO operationDTO)
        {
            this.UpdateValidation(repositorylocator, operationDTO);
            this.Name1 = operationDTO.Name1;
            this.Name2 = operationDTO.Name2;
            this.IdIdentification = operationDTO.IdIdentification;
            repositorylocator.Update(this);
        }

        private void UpdateValidation(IRepositoryLocator repositorylocator, CustomerDTO operationDTO)
        {
            return;
        }
    }
}